package img;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.File;

/**
 * @author wzby
 * @Date: 2022/8/3 9:55
 */
public class Img1 {
    public static void main(String[] args) {
        //建立图像
        int w = 300;
        int h = 255;
        BufferedImage img = new BufferedImage(w ,h ,BufferedImage.TYPE_INT_RGB);
        //RGB真彩图像

        //获取画笔
        //Graphics g1 = img.getGraphics();
        //Graphics2D g2 = (Graphics2D)img.getGraphics();
        Graphics2D g3 = img.createGraphics();
        //Graphics类提供基本绘图方法
        //Graphics2D类提供更强大的绘图能力
        Color c = new Color(250,190,20);
        g3.setColor(c);
        g3.drawString("你好",200,150);
        g3.fillOval(80,50,100,100);

        g3.dispose();
        //使用完后，释放画笔对象占用内存

        //保存自己画的img
        try {
            ImageIO.write(img,"jpg",new File("ch09/src/pho/img1.jpg"));
            //自动打开图像
            Runtime run = Runtime.getRuntime();
            run.exec("cmd /k start  ch09/src/pho/img1.jpg");
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}
